package com.ruoyi.crop.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.crop.api.domain.Business;
import com.ruoyi.crop.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 超市Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/business")
public class BusinessController extends BaseController {
    @Autowired
    private BusinessService businessService;

    /**
     * 查询超市列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Business business)
    {
        startPage();
        List<Business> list = businessService.selectBusinessList(business);
        return getDataTable(list);
    }


    /**
     * 获取超市详细信息
     */
    @GetMapping(value = "/{businessId}")
    public AjaxResult getInfo(@PathVariable("businessId") Integer businessId)
    {
        return success(businessService.getById(businessId));
    }

    /**
     * 新增超市
     */
    @PostMapping
    public AjaxResult add(@RequestBody Business business)
    {
        business.setCreateBy(SecurityUtils.getUsername());
        business.setCreateTime(new Date());
        return toAjax(businessService.save(business));
    }

    /**
     * 修改超市
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Business business)
    {
        business.setUpdateBy(SecurityUtils.getUsername());
        business.setUpdateTime(new Date());
        return toAjax(businessService.updateById(business));
    }

    /**
     * 删除超市
     */
    @DeleteMapping("/{businessIds}")
    public AjaxResult remove(@PathVariable Integer[] businessIds)
    {
        return toAjax(businessService.removeBatchByIds(Arrays.asList(businessIds)));
    }
}
